﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Controls;
using System.Xml.Serialization;
using WMPLib;

namespace MyWindowsMediaPlayer_V2
{
    [Serializable]
    public class Media
    {
        [XmlIgnore]
        public System.Windows.Controls.MediaElement mediaInstance;
        [XmlIgnore]
        public IWMPMedia media { get; set; }
        [XmlIgnore]
        public string name { get; set; }
        [XmlIgnore]
        public string image { get; set; }
        [XmlIgnore]
        public string totalDuration { get; set; }
        [XmlIgnore]
        public double duration { get; set; }
        [XmlIgnore]
        public string artiste { get; set; }
        [XmlIgnore]
        public short type { get; set; }
        [XmlIgnore]
        public TimeSpan timespan { get; set; }
        public string path { get; set; }

        public Media()
        {
        }
        public void setNameFrom_Path(string path)
        {
            this.path = path;
            name = name = path.Split(new Char[] { '\\' }).Last();
        }
        public string getPath()
        {
            return (path);
        }
        public void setMediaInstance(System.Windows.Controls.MediaElement mediaElement)
        {
            mediaInstance = mediaElement;
        }
        public void play_Media()
        {
            if (mediaInstance.Source != null)
                stop_Media();
            mediaInstance.Source = new Uri(path);
            if (type != 2)
            {
                MediaClock clock = mediaInstance.Clock;

                MediaTimeline timeline = new MediaTimeline(mediaInstance.Source);
                clock = timeline.CreateClock();
                mediaInstance.Clock = clock;
            }
            mediaInstance.Play();
        }
        public void stop_Media()
        {
            mediaInstance.Clock = null;
            mediaInstance.Stop();
        }
        public string getName()
        {
            return (name);
        }
        public void setWmp(IWMPMedia Media)
        {
            media = Media;
            totalDuration = media.durationString;
            duration = media.duration;
            artiste = media.getItemInfo("Author");
        }
        public string getImage()
        {
            return (image);
        }
        public string getTotal_Duration()
        {
            return (totalDuration);
        }
        public void setImage(string imagePath)
        {
            image = imagePath;
        }
    }
}
